/*
var doAnimation = require("../plugin/animation/request-animation-frame"); 
*/

var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame;
var caf = window.cancelAnimationFrame || window.mozCancelAnimationFrame;


module.exports = animate;
function animate(elem,from,to,done){
	var rafId,diff,duration,start,progress;
		from = parseInt(from, 10);
		to = parseInt(to, 10);
		diff = to - from;
		duration = 500;
		progress = 0;
		elem.style.webkitTransform = 'translate3d(' + from + 'px, 0,0)';
	function step(timestamp){
		if (!start) {
			start = timestamp;
			rafId = raf(step);
			return;
		}
		progress = (timestamp - start) / duration;
		if(progress>=1){
			elem.style.visibility='visible';
			elem.style.webkitTransform = 'translate3d('+to+'px,0,0)';// 动画完成
			caf(rafId);
		//	start = null;
		}else{
			elem.style.webkitTransform = 'translate3d('+(from + progress*diff)+'px,0,0)';// 动画进行中
			rafId = raf(step);
		}	
	}
	rafId = raf(step);
}